import React from 'react';
import Child2 from './Child2';

export class Parent2 extends React.Component {
  constructor() {
    super();
    this.state = {
      money: 0,
    };
  }

  // 父组件定义传递数据的函数
  giveMoney = (money) => {
    console.log('子组件传递的数据', money);
    this.setState({
      money: money,
    });
  };

  render() {
    return (
      <div style={{ border: '1px solid red', padding: 24 }}>
        <h1>儿子问我要钱了{this.state.money}</h1>
        <Child2 giveMoneyXxx={this.giveMoney} />
      </div>
    );
  }
}

export default Parent2;
